package com.liy.supercloud.ssoserver.controller;

import com.liy.framework.common.extvo.ResultVO;
import com.liy.framework.web.spring.controller.SupportController;
import com.liy.supercloud.ssoserver.config.AuthKeyConfig;
import com.liy.supercloud.ssoserver.service.AuthorizationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


/**
 * sso-client 的项目(依赖他即可), 将会消费: sso-server 这里的服务, 通过 feign
 *
 * @see  # com.liy.supercloud.ssoclient.feign.AuthorizationFeignClient
 *
*/
@RestController
@RequestMapping({"/auth/authorization"})
public class UserAuthorizationController extends SupportController {


    /*
     * 授权服务
     */
    @Autowired
    private AuthorizationService authorizationService;



    @Autowired
    private AuthKeyConfig keyConfig;


    /*
     * 根服务
     */
    @RequestMapping(value = "/", method = {RequestMethod.POST})
    @ResponseBody
    public ResultVO authorization(String token) {
        return this.authorizationService.authorization(token);
    }


    @ResponseBody
    @RequestMapping({"/userPubKey"})
    public ResultVO getServicePublicKey(String clientId, String secret) throws Exception {
        ResultVO resultVO = new ResultVO();
        resultVO.setData(this.keyConfig.getUserPubKey());
        resultVO.setMessage("Authentication Successful.");
        return resultVO;
    }


    @RequestMapping(value = {"/hasPermission"}, method = {RequestMethod.POST})
    @ResponseBody
    public ResultVO hasPermission(String token, String code) {
        log.debug(">>>>开始认证,Token::" + token + ", Code:" + code);
        return this.authorizationService.hasPermission(token, code);
    }
}
